/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelInterfaces.java
 *
 * Created on 12/03/2011, 18:31:03
 */

package tsb.UI.Paneles;

import tsb.dominio.interfaces.IP;
import tsb.UI.Ventanas.VentanaDeError;
import tsb.dominio.enumeraciones.AsignacionIP;
/**
 *
 * @author Federico Gomez
 */
public class PanelInterfaces extends javax.swing.JPanel {

    /** Creates new form PanelInterfaces */
    public PanelInterfaces() {
        initComponents();
        
    }

    public boolean estado()
    {
        if(this.cmbEstado.getSelectedIndex()==0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int getAnchoDeBanda()
    {
        if(this.rbtn10.isSelected())
        {
            return 10;
        }
        if(this.rbtn100.isSelected())
        {
            return 100;
        }

        return 1000;

    }

    public boolean getDeteccionAutomaticaAnchoBanda()
    {
        if(this.chkAnchoBanda.isSelected())
        {return true;}
        else
        {return false;}
    }

    public IP getIP()
    {
        IP ip=null;
        
            String cad=this.txtIP.getText();
            if(IP.comprobrarIP(cad))
            {
                    ip = new IP(cad);
            }
            else
            {return null;}
        
        return ip;
    }

    public IP getMascara()
    {
        try
        {
            IP ip = new IP(this.txtMascara.getText());
            return ip;
        }
        catch(Exception e)
        {}
        return null;


    }
    
    public void setEncendido(String a)
    {
        if(a.compareTo("Si")==0)
            this.cmbEstado.setSelectedIndex(0);
        else
            this.cmbEstado.setSelectedIndex(1);
    }
    
    public void setAuto(boolean b)
    {
        this.chkAnchoBanda.setSelected(b);
    }
    
    public void setAnchoBada(int ancho)
    {
        if(ancho==10)
        {
            this.rbtn10.setSelected(true);
        }
        else
        {
            if(ancho==100)
            {
                this.rbtn100.setSelected(true);
            }
            else
            {
                this.rbtn1000.setSelected(true);
    }   }   }
    
    public void setIP(IP ip)
    {
        this.txtIP.setText(ip.toString());
    }
    
    public void setMascara(IP m)
    {
        this.txtMascara.setText(m.toString());
    }
    
    public boolean verificar()
    {
        if(!this.rbtn10.isSelected())
        {
            if(!this.rbtn100.isSelected())
            {
                if(!this.rbtn1000.isSelected())
                {
                    VentanaDeError.mostrarDialog("ERROR", "Debe seleccionar una velocidad de ancho de banda", 2);
                    return false;
        }   }   }
        
        if(this.txtIP.getText().compareTo("")==0)
        {
            VentanaDeError.mostrarDialog("ERROR", "Debe ingresar una IP", 2);
            return false;
        }
        
        if(!IP.comprobrarIP(this.txtIP.getText()))
        {
            VentanaDeError.mostrarDialog("ERROR", "               La IP ingresada no es valido.\n Debe terner el formato 1.1.1.1 con numeros entre 0 y 255", 2);
            return false;
        }
        
         if(this.txtMascara.getText().compareTo("")==0)
         {
             VentanaDeError.mostrarDialog("ERROR", "Debe ingresar una MAC", 2);
            return false;
         }
         if(!IP.comprobrarIP(this.txtMascara.getText()))
         {
            VentanaDeError.mostrarDialog("ERROR", "               La mascara ingresada no es valida.\n Debe terner el formato 1.1.1.1 con numeros entre 0 y 255", 2);
            return false;
         }
         
         return true;
    }
    
    public void habilitarAuto(boolean b)
    {
        this.chkAnchoBanda.setEnabled(b);
    }
    
    public void habilitarAnchoBanda(int a)
    {
        if(a==10)
        {
            this.rbtn10.setEnabled(true);
            this.rbtn100.setEnabled(false);
            this.rbtn1000.setEnabled(false);
        }
        else
        {
            if(a==100)
            {
                this.rbtn10.setEnabled(false);
                this.rbtn100.setEnabled(true);
                this.rbtn1000.setEnabled(false);
            }
            else
            {
                this.rbtn10.setEnabled(false);
                this.rbtn100.setEnabled(false);
                this.rbtn1000.setEnabled(true);
            } 
        }
    }
    
    public void setAsignacionIP(AsignacionIP asignacion)
    {
        if(asignacion == AsignacionIP.DCHP)
        {
            this.rbtDHCP.setSelected(true);
            this.txtIP.setEnabled(false);
            this.txtMascara.setEnabled(false);
        }
        else
        {
            this.rbtStatic.setSelected(true);
            this.txtIP.setEnabled(true);
            this.txtMascara.setEnabled(true);
        }
        
    } 

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bGroupAnchoBanda = new javax.swing.ButtonGroup();
        btngAsignaiconIP = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        chkAnchoBanda = new javax.swing.JCheckBox();
        rbtn10 = new javax.swing.JRadioButton();
        rbtn100 = new javax.swing.JRadioButton();
        rbtn1000 = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtIP = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtMascara = new javax.swing.JTextField();
        rbtDHCP = new javax.swing.JRadioButton();
        rbtStatic = new javax.swing.JRadioButton();

        setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setText("Encendido:");

        cmbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "      Si ", "      No" }));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ancho de Banda"));
        jPanel1.setAlignmentX(0.3F);
        jPanel1.setAlignmentY(0.3F);

        chkAnchoBanda.setBackground(new java.awt.Color(255, 255, 255));
        chkAnchoBanda.setFont(new java.awt.Font("Tahoma", 0, 14));
        chkAnchoBanda.setSelected(true);
        chkAnchoBanda.setText("Auto");
        chkAnchoBanda.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chkAnchoBandaMouseClicked(evt);
            }
        });

        rbtn10.setBackground(new java.awt.Color(255, 255, 255));
        bGroupAnchoBanda.add(rbtn10);
        rbtn10.setFont(new java.awt.Font("Tahoma", 0, 14));
        rbtn10.setText("10");
        rbtn10.setEnabled(false);

        rbtn100.setBackground(new java.awt.Color(255, 255, 255));
        bGroupAnchoBanda.add(rbtn100);
        rbtn100.setFont(new java.awt.Font("Tahoma", 0, 14));
        rbtn100.setText("100");
        rbtn100.setEnabled(false);

        rbtn1000.setBackground(new java.awt.Color(255, 255, 255));
        bGroupAnchoBanda.add(rbtn1000);
        rbtn1000.setFont(new java.awt.Font("Tahoma", 0, 14));
        rbtn1000.setSelected(true);
        rbtn1000.setText("1000");
        rbtn1000.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbtn10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtn100)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtn1000))
                    .addComponent(chkAnchoBanda))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(chkAnchoBanda)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtn10)
                    .addComponent(rbtn100)
                    .addComponent(rbtn1000)))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Configuración IP"));
        jPanel2.setAlignmentX(0.0F);
        jPanel2.setAlignmentY(0.0F);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("IP");

        txtIP.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtIP.setEnabled(false);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Mascara");

        txtMascara.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtMascara.setEnabled(false);

        rbtDHCP.setBackground(new java.awt.Color(255, 255, 255));
        btngAsignaiconIP.add(rbtDHCP);
        rbtDHCP.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbtDHCP.setSelected(true);
        rbtDHCP.setText("DHCP");
        rbtDHCP.setToolTipText("Se podra cambiar la forma de asignación de IP en la pestaña Configuraciones");
        rbtDHCP.setEnabled(false);
        rbtDHCP.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rbtDHCPMouseClicked(evt);
            }
        });

        rbtStatic.setBackground(new java.awt.Color(255, 255, 255));
        btngAsignaiconIP.add(rbtStatic);
        rbtStatic.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbtStatic.setText("Static");
        rbtStatic.setToolTipText("Se podra cambiar la forma de asignación de IP en la pestaña Configuraciones");
        rbtStatic.setEnabled(false);
        rbtStatic.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rbtStaticMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtIP, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                            .addComponent(txtMascara, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)))
                    .addComponent(rbtDHCP)
                    .addComponent(rbtStatic))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(rbtDHCP)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbtStatic)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtMascara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void chkAnchoBandaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chkAnchoBandaMouseClicked
        
        if(this.chkAnchoBanda.isSelected())
        { this.rbtn10.setEnabled(false);
            this.rbtn100.setEnabled(false);
            this.rbtn1000.setEnabled(false);
        }
        else
        {
           this.rbtn10.setEnabled(true);
           this.rbtn100.setEnabled(true);
           this.rbtn1000.setEnabled(true);
        }
    }//GEN-LAST:event_chkAnchoBandaMouseClicked

    private void rbtDHCPMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rbtDHCPMouseClicked

        VentanaDeError.mostrarDialog("Cambio de Asiganción IP", "Se podra cambiar la forma de asignación de IP en la pestaña Configuraciones", 2);
    }//GEN-LAST:event_rbtDHCPMouseClicked

    private void rbtStaticMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rbtStaticMouseClicked
       VentanaDeError.mostrarDialog("Cambio de Asiganción IP", "Se podra cambiar la forma de asignación de IP en la pestaña Configuraciones", 2);
    }//GEN-LAST:event_rbtStaticMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bGroupAnchoBanda;
    private javax.swing.ButtonGroup btngAsignaiconIP;
    private javax.swing.JCheckBox chkAnchoBanda;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton rbtDHCP;
    private javax.swing.JRadioButton rbtStatic;
    private javax.swing.JRadioButton rbtn10;
    private javax.swing.JRadioButton rbtn100;
    private javax.swing.JRadioButton rbtn1000;
    private javax.swing.JTextField txtIP;
    private javax.swing.JTextField txtMascara;
    // End of variables declaration//GEN-END:variables

}
